package com.example.kliven.because.fragment;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.kliven.because.R;
import com.example.kliven.because.adapter.MessageAdapter;
import com.example.kliven.because.adapter.MessagePagerAdapter;

import java.util.ArrayList;

public class MessageFragment extends Fragment implements View.OnClickListener {
    public static final int TAB_COMMEND = 0;
    public static final int TAB_NOTIFY = 1;
    public static final int TAB_PRIVATE_MSG = 2;
    private RadioGroup radioGroup;
    private RadioButton btn_commend,btn_notify,btn_privateMsg;
    private ViewPager viewPager;
    private MessagePagerAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.message_fragment, null);
        viewPager = (ViewPager) view.findViewById(R.id.view_Pager);
        radioGroup = (RadioGroup) view.findViewById(R.id.radio_group);
        btn_commend = (RadioButton) view.findViewById(R.id.radio_btn_commend);
        btn_notify = (RadioButton) view.findViewById(R.id.radio_btn_notify);
        btn_privateMsg = (RadioButton) view.findViewById(R.id.radio_btn_private_msg);

        radioGroup.check(R.id.radio_btn_share);
        btn_commend.setOnClickListener(this);
        btn_notify.setOnClickListener(this);
        btn_privateMsg.setOnClickListener(this);

        adapter = new MessagePagerAdapter(getActivity().getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        addListener();
        return view;
    }

    private void addListener() {
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int id) {
                switch (id) {
                    case TAB_COMMEND:
                        btn_commend.setChecked(true);
                        break;
                    case TAB_NOTIFY:
                        btn_notify.setChecked(true);
                        break;
                    case TAB_PRIVATE_MSG:
                        btn_privateMsg.setChecked(true);
                        break;
                }
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.radio_btn_commend:
                viewPager.setCurrentItem(TAB_COMMEND);
                break;
            case R.id.radio_btn_notify:
                viewPager.setCurrentItem(TAB_NOTIFY);
                break;
            case R.id.radio_btn_private_msg:
                viewPager.setCurrentItem(TAB_PRIVATE_MSG);
                break;

        }
    }
}